import logging
import os.path
import time


class InfoFilter(logging.Filter):
    def filter(self, record):
        return record.levelno == logging.INFO


class ErrorFilter(logging.Filter):
    def filter(self, record):
        return record.levelno == logging.ERROR


class Logger:
    @classmethod
    def getlog(cls):
        cls.logger = logging.getLogger(__name__)
        cls.logger.setLevel(logging.DEBUG)

        now = time.strftime("%Y-%m-%d")
        LOG_PATH = 'logs/'
        if not os.path.exists(LOG_PATH):
            os.makedirs(LOG_PATH)
        info_log_name = LOG_PATH + now + '_info.log'
        error_log_name = LOG_PATH + now + '_error.log'
        log_name = LOG_PATH + now + '.log'

        handler = logging.FileHandler(log_name, encoding='utf-8')
        handler.setLevel(logging.INFO)

        info_handler = logging.FileHandler(info_log_name, encoding='utf-8')
        info_handler.setLevel(logging.INFO)
        info_handler.addFilter(InfoFilter())

        error_handler = logging.FileHandler(error_log_name, encoding='utf-8')
        error_handler.setLevel(logging.ERROR)
        error_handler.addFilter(ErrorFilter())

        formatter = logging.Formatter(
            "%(asctime)s %(levelname)s [%(name)s] [%(filename)s (%(funcName)s:%(lineno)d] - %(message)s"
        )

        handler.setFormatter(formatter)
        info_handler.setFormatter(formatter)
        error_handler.setFormatter(formatter)

        cls.logger.addHandler(handler)
        cls.logger.addHandler(info_handler)
        cls.logger.addHandler(error_handler)

        return cls.logger
